package com.example.dataservice.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.example.api.model.ProductInfo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

public interface ProductInfoMapper {

    @Select("""
            select count(*) as nums from b_product_info where product_type = #{productType};
            """)
            @ResultType(Integer.class)
    /*查询某个产品总数*/
    Integer selectCountByType(@Param("productType") Integer productType);

    @Select("""
            select * from b_product_info where product_type = #{productType} limit #{offset}, #{rows};
            """)
    /*按产品的类型分页查询*/
    List<ProductInfo> selectByTypeLimit(@Param("productType") Integer productType,
                                        @Param("offset") Integer offset,
                                        @Param("rows") Integer rows);

    @Select("""
            select * from b_product_info;
            """)
    /*查询所有的产品信息*/
    List<ProductInfo> selectAll();

    @Select("""
            select round(avg(rate),2) as avgRate from b_product_info;
            """)
    @ResultType(BigDecimal.class)
        /*利率平均值*/
    BigDecimal selectAvgRate();


    int deleteByPrimaryKey(Integer id);

    int insert(ProductInfo record);

    int insertSelective(ProductInfo record);

    ProductInfo selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(ProductInfo record);

    int updateByPrimaryKey(ProductInfo record);


    @Select("""
            select * from b_product_info
            where product_status = #{productStatus}
            and product_full_time >= #{begin} 
            and product_full_time < #{end}
            order by id
            """)
    /*查询在某个时间段的某个状态的所有产品*/
    List<ProductInfo> selectStatusProduct(@Param("productStatus") int productStatus,
                             @Param("begin") Date begin,
                             @Param("end") Date end);
}